package com.sfc.client;

import com.sfc.client.constant.ConfigConstants;
import com.sfc.client.handler.BindHandler;
import com.sfc.client.sdk.CIMEventBroadcastReceiver;
import com.sfc.client.sdk.CIMPushManager;
import com.sfc.client.util.PropertiesUtil;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author lizhenwei
 * @version 1.0
 * @date 2021/4/13 19:11
 */
public class ClientStarter {

    private static final String ip;
    private static final int port;
    private static final String client_version;

    static {
        ip = PropertiesUtil.getString(ConfigConstants.CONFIG_FILE_PATH, ConfigConstants.NETTY_CONNECT_IP);
        port = PropertiesUtil.getInt(ConfigConstants.CONFIG_FILE_PATH, ConfigConstants.NETTY_CONNECT_PORT);
        client_version = PropertiesUtil.getString(ConfigConstants.CONFIG_FILE_PATH, ConfigConstants.NETTY_CONNECT_VERSION);
    }

    public static void startup() {
        /*
         * 第一步 设置运行时参数
         */
        CIMPushManager.setClientVersion(client_version);


        /*
         * 第二步 设置全局的事件监听器
         */
        CIMEventBroadcastReceiver.getInstance().setGlobalCIMEventListener(new BindHandler());

        /*
         * 第三步 连接到服务器
         */
        CIMPushManager.connect(ip, port);

    }

    private static void read() throws Exception {
        Process proc = Runtime.getRuntime().exec("net user");

        InputStream is = proc.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
        proc.waitFor();
        is.close();
        reader.close();
        proc.destroy();
        System.out.println();


    }

    public static void main(String[] args) throws Exception {

    }
}
